package com.example.zzj.ziwuyundemo.fragment;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.zzj.ziwuyundemo.R;
import com.example.zzj.ziwuyundemo.activity.ChangePassActivity;
import com.example.zzj.ziwuyundemo.activity.LoginActivity;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by zzj on 2016/11/22.
 */

public class MessageFragment extends Fragment implements View.OnClickListener {

    @InjectView(R.id.tv_user)
    TextView tvUser;
    @InjectView(R.id.img_user)
    ImageView imgUser;
    @InjectView(R.id.tv_modify)
    TextView tvModify;
    @InjectView(R.id.modify_jump)
    ImageView modifyJump;
    @InjectView(R.id.tv_announcement)
    TextView tvAnnouncement;
    @InjectView(R.id.announcement_jump)
    ImageView announcementJump;
    @InjectView(R.id.tv_vertical)
    TextView tvVertical;
    @InjectView(R.id.vertical_jump)
    ImageView verticalJump;
    @InjectView(R.id.tv_assessment)
    TextView tvAssessment;
    @InjectView(R.id.assessment_jump)
    ImageView assessmentJump;
    @InjectView(R.id.tv_settlement)
    TextView tvSettlement;
    @InjectView(R.id.settlement_jump)
    ImageView settlementJump;
    @InjectView(R.id.tv_malfunction)
    TextView tvMalfunction;
    @InjectView(R.id.malfunction_jump)
    ImageView malfunctionJump;
    @InjectView(R.id.rl_modify)
    RelativeLayout rlModify;
    @InjectView(R.id.rl_announcement)
    RelativeLayout rlAnnouncement;
    @InjectView(R.id.rl_vertical)
    RelativeLayout rlVertical;
    @InjectView(R.id.rl_assessment)
    RelativeLayout rlAssessment;
    @InjectView(R.id.rl_settlement)
    RelativeLayout rlSettlement;
    @InjectView(R.id.rl_malfunction)
    RelativeLayout rlMalfunction;
    @InjectView(R.id.out)
    Button out;
    private String photos;
    private String name;
    private String userId;
    private Context context;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_message, container, false);
        ButterKnife.inject(this, view);
        initView();
        initData();
        return view;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.context = activity;
    }

    private void initView() {
        Intent intent = getActivity().getIntent();
        photos = intent.getStringExtra("photo");
        name = intent.getStringExtra("userN");
        userId  = intent.getStringExtra("id");
        tvUser.setText(name);
        if (photos.equals("")){

        }else {
            Glide.with(context).load(photos).into(imgUser);
        }

    }

    private void initData() {
        tvUser.setOnClickListener(this);
        imgUser.setOnClickListener(this);
        rlModify.setOnClickListener(this);
        rlAnnouncement.setOnClickListener(this);
        rlVertical.setOnClickListener(this);
        rlAssessment.setOnClickListener(this);
        rlSettlement.setOnClickListener(this);
        rlMalfunction.setOnClickListener(this);
        out.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.tv_user:
                break;
            case R.id.img_user:
//                intent = new Intent(getActivity(), LoginActivity.class);
//                startActivity(intent);
                break;
            case R.id.rl_modify:
                intent = new Intent(getActivity(), ChangePassActivity.class);
                intent.putExtra("userId",userId);
                startActivity(intent);
                break;
            case R.id.rl_announcement:
                break;
            case R.id.rl_vertical:
//                AnswerFragment answerFragment = new AnswerFragment();
//                FragmentManager fragmentManager = getFragmentManager();
//                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
//                fragmentTransaction.replace(R.id.viewPager,answerFragment);
//                fragmentTransaction.commit();
                break;
            case R.id.rl_assessment:
                break;
            case R.id.rl_settlement:
                break;
            case R.id.rl_malfunction:
                break;
            case R.id.out:
                intent = new Intent(getActivity(),LoginActivity.class);
                startActivity(intent);
                getActivity().finish();
                break;
        }
    }
}
